<?php

/**
 * This is the model class for table "hist_claim_anggota".
 *
 * The followings are the available columns in table 'hist_claim_anggota':
 * @property integer $id
 * @property integer $id_hist_claim
 * @property string $karyawan
 * @property string $tgl_claim
 * @property double $nominal
 * @property string $plan
 * @property integer $createdby
 * @property string $createdtime
 * @property integer $updatedby
 * @property string $updatedtime
 * @property string $peserta
 * @property string $no_reg
 * @property double $jumlah_dibayar
 * @property string $tgl_pembayaran
 */
class HistClaimAnggota extends CActiveRecord
{
	public $nota_debet_no;
	public $policy_no;
	public $trx_date;
	
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'hist_claim_anggota';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('karyawan, tgl_claim', 'required'),
			array('id_hist_claim, createdby, updatedby', 'numerical', 'integerOnly'=>true),
			array('nominal, jumlah_dibayar', 'numerical'),
			array('karyawan, peserta, tgl_claim2', 'length', 'max'=>100),
			array('plan', 'length', 'max'=>50),
			array('no_reg', 'length', 'max'=>20),
			array('tgl_pembayaran, tgl_claim2', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, id_hist_claim, karyawan, tgl_claim, tgl_claim2, nominal, plan, createdby, createdtime, updatedby, updatedtime, peserta, no_reg, jumlah_dibayar, tgl_pembayaran', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'id_hist_claim' => 'Id Hist Claim',
			'karyawan' => 'Karyawan',
			'tgl_claim' => 'Tgl Claim',
			'nominal' => 'Nominal',
			'plan' => 'Plan',
			'createdby' => 'Createdby',
			'createdtime' => 'Createdtime',
			'updatedby' => 'Updatedby',
			'updatedtime' => 'Updatedtime',
			'peserta' => 'Peserta',
			'no_reg' => 'No Reg',
			'jumlah_dibayar' => 'Jumlah Dibayar',
			'tgl_pembayaran' => 'Tgl Pembayaran',
			'tgl_claim' => 'Tgl Claim',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('id_hist_claim',$this->id_hist_claim);
		$criteria->compare('karyawan',$this->karyawan,true);
		$criteria->compare('tgl_claim',$this->tgl_claim,true);
		$criteria->compare('nominal',$this->nominal);
		$criteria->compare('plan',$this->plan,true);
		$criteria->compare('createdby',$this->createdby);
		$criteria->compare('createdtime',$this->createdtime,true);
		$criteria->compare('updatedby',$this->updatedby);
		$criteria->compare('updatedtime',$this->updatedtime,true);
		$criteria->compare('peserta',$this->peserta,true);
		$criteria->compare('no_reg',$this->no_reg,true);
		$criteria->compare('jumlah_dibayar',$this->jumlah_dibayar);
		$criteria->compare('tgl_pembayaran',$this->tgl_pembayaran,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}



	public function searchView($id)
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;
		$criteria->select = 't.id, b.nota_debet_no, b.policy_no, b.trx_date, t.karyawan, t.tgl_claim, t.tgl_claim2, t.nominal, t.plan, t.peserta, t.no_reg, t.jumlah_dibayar, t.tgl_pembayaran, t.createdtime';
		$criteria->join = 'join hist_claim b on t.id_hist_claim = b.id';
		$criteria->condition = 'b.id='.$id;

		$criteria->compare('id',$this->id);
		$criteria->compare('id_hist_claim',$this->id_hist_claim);
		$criteria->compare('karyawan',$this->karyawan,true);
		$criteria->compare('tgl_claim',$this->tgl_claim,true);
		$criteria->compare('nominal',$this->nominal);
		$criteria->compare('plan',$this->plan,true);
		$criteria->compare('createdby',$this->createdby);
		$criteria->compare('createdtime',$this->createdtime,true);
		$criteria->compare('updatedby',$this->updatedby);
		$criteria->compare('updatedtime',$this->updatedtime,true);
		$criteria->compare('peserta',$this->peserta,true);
		$criteria->compare('no_reg',$this->no_reg,true);
		$criteria->compare('jumlah_dibayar',$this->jumlah_dibayar);
		$criteria->compare('tgl_pembayaran',$this->tgl_pembayaran,true);		

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}


	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return HistClaimAnggota the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}


	public function getStatus($status){

		switch ($status) {
			case '1': $printStatus = 'New Claim';break;
			case '2': $printStatus = 'Ditunda';break;
			case '3': $printStatus = 'Re-Claim';break;
			case '4': $printStatus = 'Diterima';break;
			case '5': $printStatus = 'Ditolak';break;
			default:break;
		}

		return $printStatus;
	}
}
